﻿namespace Sidvall.Web.IO
{
    public class ServiceManagerContext
    {
        public StoreCollection Stores { get; set; }
        public string AuthorizationProviderFactory { get; set; }
        public string AuthorizationProviderFactoryContext { get; set; }

        #region Deserialize

        public static ServiceManagerContext Deserialize(string value)
        {
            return Deserialize(value, null);
        }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        public static ServiceManagerContext Deserialize(string value, ServiceManagerContext defaultValue)
        {
            if (string.IsNullOrWhiteSpace(value))
                return defaultValue;
            try
            {
                return Sidvall.Serialization.SerializerManager.Current.Deserialize<ServiceManagerContext>(value);
            }
            catch
            {
                return defaultValue;
            }
        }

        #endregion
        #region Serialize

        public string Serialize()
        {
            return Serialize(this);
        }
        public static string Serialize(ServiceManagerContext context)
        {
            return Sidvall.Serialization.SerializerManager.Current.SerializeObject(context);
        }

        #endregion
    }
}
